package com.ruoyi.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.blog.domain.BlogArticleLabel;
import com.ruoyi.blog.mapper.BlogArticleLabelMapper;
import com.ruoyi.blog.service.BlogArticleLabelService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class BlogArticleLabelServiceImpl extends ServiceImpl<BlogArticleLabelMapper, BlogArticleLabel> implements BlogArticleLabelService {

    @Override
    public void updateArticleLabel(String articleId, List<Long> labelIds) {
        // 删除之前所有文章与标签的关联
        remove(lambdaQuery().eq(BlogArticleLabel::getArticleId, articleId).getWrapper());
        // 添加新的文章与标签的关联
        labelIds.forEach(n -> save(BlogArticleLabel.builder().articleId(articleId).labelId(n).build()));
    }

}
